package com.cc.service;

import com.cc.config.YamlOtherConfiguration;
import com.cc.pojo.WhereParams;
import com.cc.pojo.dto.ParametersDto;
import com.cc.pojo.tablestruct.NeedQueryParams;
import com.cc.service.generate.GenerateController;
import com.cc.service.generate.GenerateDao;
import com.cc.service.generate.GenerateDaoImpl;
import com.cc.service.generate.GenerateDb;
import com.cc.service.generate.GenerateDo;
import com.cc.service.generate.GenerateDto;
import com.cc.service.generate.GenerateInter;
import com.cc.service.generate.GenerateService;
import com.cc.service.generate.GenerateVo;
import com.cc.utils.beanUtil.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.velocity.app.Velocity;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

/**
 * @User c.c
 * @Since 2023/4/19
 * @Time 19:04
 * @Description
 */

@Service
@Slf4j
public class GenerateJavaService {


  /**
   * 生成实体类
   *
   * @param tableMaps 前端传递参数
   * @return string 生成路径
   * @author C.c
   * @since 2023-05-12 08:38
   **/

  public void generate(Map<String, List<ParametersDto>> tableMaps) {
    //转换参数
    HashMap<String, List<NeedQueryParams>> needQueryMap = new HashMap<>();
    HashMap<String, List<WhereParams>> whereMap = new HashMap<>();
    tableMaps.forEach((k, v) -> {
      List<NeedQueryParams> needQueryParams = v.stream().map(NeedQueryParams::convertNeedQueryParamsByParametersDto).collect(Collectors.toList());
      List<WhereParams> whereParams = v.stream().map(WhereParams::convertWhereParamsByParametersDto).collect(Collectors.toList());
      whereMap.put(k, whereParams);
      needQueryMap.put(k, needQueryParams);

    });

    log.info("--------------------开始生成文件------------------------");
    long ago = System.currentTimeMillis();

    GenerateDb generateDb = new GenerateDb();
    GenerateDo generateDo = new GenerateDo();
    GenerateVo generateVo = new GenerateVo();
    GenerateDto generateDto = new GenerateDto();

    GenerateDao generateDao = new GenerateDao(needQueryMap);
    GenerateInter generateInter = new GenerateInter();

    GenerateDaoImpl generateDaoimpl = new GenerateDaoImpl(needQueryMap, whereMap);

    GenerateService generateService = new GenerateService(needQueryMap);
    GenerateController generateController = new GenerateController(needQueryMap);


    log.info("生成所用时间：" + Long.divideUnsigned(System.currentTimeMillis() - ago, 1000) + "s");
  }
}
